<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="入库单号" prop="jumboPlatesStockInId">
        <el-input
          v-model="queryParams.jumboPlatesStockInId"
          placeholder="请输入入库单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原片ID" prop="jumboPlatesId">
        <el-input
          v-model="queryParams.jumboPlatesId"
          placeholder="请输入原片ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="宽度" prop="jumboPlatesWidth">
        <el-input
          v-model="queryParams.jumboPlatesWidth"
          placeholder="请输入宽度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="高度" prop="jumboPlatesHeight">
        <el-input
          v-model="queryParams.jumboPlatesHeight"
          placeholder="请输入高度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="质量等级" prop="jumboPlatesQualityLevel">
        <el-input
          v-model="queryParams.jumboPlatesQualityLevel"
          placeholder="请输入质量等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库箱数" prop="jumboPlatesStockInBoxQuantity">
        <el-input
          v-model="queryParams.jumboPlatesStockInBoxQuantity"
          placeholder="请输入入库箱数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入数" prop="jumboPlatesPiecePerBox">
        <el-input
          v-model="queryParams.jumboPlatesPiecePerBox"
          placeholder="请输入入数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="散片数量" prop="jumboPlatesStockInUnpackaged">
        <el-input
          v-model="queryParams.jumboPlatesStockInUnpackaged"
          placeholder="请输入散片数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单价" prop="jumboPlatesPrice">
        <el-input
          v-model="queryParams.jumboPlatesPrice"
          placeholder="请输入单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库ID" prop="stockId">
        <el-input
          v-model="queryParams.stockId"
          placeholder="请输入仓库ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="货位ID" prop="positionId">
        <el-input
          v-model="queryParams.positionId"
          placeholder="请输入货位ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制造商ID" prop="manfactureId">
        <el-input
          v-model="queryParams.manfactureId"
          placeholder="请输入制造商ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商ID" prop="supplierId">
        <el-input
          v-model="queryParams.supplierId"
          placeholder="请输入供应商ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库日期" prop="jumboPlatesStockInDate">
        <el-date-picker clearable
          v-model="queryParams.jumboPlatesStockInDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择入库日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="生产日期" prop="jumboPlatesProductionDate">
        <el-date-picker clearable
          v-model="queryParams.jumboPlatesProductionDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择生产日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="数量汇总" prop="jumboPlatesQuantitySubtotal">
        <el-input
          v-model="queryParams.jumboPlatesQuantitySubtotal"
          placeholder="请输入数量汇总"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面积汇总" prop="jumboPlatesSurfaceSubtotal">
        <el-input
          v-model="queryParams.jumboPlatesSurfaceSubtotal"
          placeholder="请输入面积汇总"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="金额汇总" prop="jumboPlatesValueSubtotal">
        <el-input
          v-model="queryParams.jumboPlatesValueSubtotal"
          placeholder="请输入金额汇总"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="memo">
        <el-input
          v-model="queryParams.memo"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="冲单标志" prop="undoFlag">
        <el-input
          v-model="queryParams.undoFlag"
          placeholder="请输入冲单标志"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人" prop="checker">
        <el-input
          v-model="queryParams.checker"
          placeholder="请输入审核人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车台号" prop="rackId">
        <el-input
          v-model="queryParams.rackId"
          placeholder="请输入车台号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产线" prop="floatLine">
        <el-input
          v-model="queryParams.floatLine"
          placeholder="请输入生产线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="重量汇总" prop="jumboPlatesWeightSubtotal">
        <el-input
          v-model="queryParams.jumboPlatesWeightSubtotal"
          placeholder="请输入重量汇总"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="玻璃额外信息" prop="glassAdditionalInformation">
        <el-input
          v-model="queryParams.glassAdditionalInformation"
          placeholder="请输入玻璃额外信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数量" prop="deductionSqm">
        <el-input
          v-model="queryParams.deductionSqm"
          placeholder="请输入数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="列" prop="rows">
        <el-input
          v-model="queryParams.rows"
          placeholder="请输入列"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除时间" prop="inputDate">
        <el-date-picker clearable
          v-model="queryParams.inputDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择删除时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:in:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:in:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:in:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:in:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="inList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="keyId" />
      <el-table-column label="入库单号" align="center" prop="jumboPlatesStockInId" />
      <el-table-column label="原片ID" align="center" prop="jumboPlatesId" />
      <el-table-column label="宽度" align="center" prop="jumboPlatesWidth" />
      <el-table-column label="高度" align="center" prop="jumboPlatesHeight" />
      <el-table-column label="质量等级" align="center" prop="jumboPlatesQualityLevel" />
      <el-table-column label="入库箱数" align="center" prop="jumboPlatesStockInBoxQuantity" />
      <el-table-column label="入数" align="center" prop="jumboPlatesPiecePerBox" />
      <el-table-column label="散片数量" align="center" prop="jumboPlatesStockInUnpackaged" />
      <el-table-column label="单价" align="center" prop="jumboPlatesPrice" />
      <el-table-column label="入库类型" align="center" prop="jumboPlatesStockInType" />
      <el-table-column label="仓库ID" align="center" prop="stockId" />
      <el-table-column label="货位ID" align="center" prop="positionId" />
      <el-table-column label="制造商ID" align="center" prop="manfactureId" />
      <el-table-column label="供应商ID" align="center" prop="supplierId" />
      <el-table-column label="入库日期" align="center" prop="jumboPlatesStockInDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jumboPlatesStockInDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产日期" align="center" prop="jumboPlatesProductionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jumboPlatesProductionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数量汇总" align="center" prop="jumboPlatesQuantitySubtotal" />
      <el-table-column label="面积汇总" align="center" prop="jumboPlatesSurfaceSubtotal" />
      <el-table-column label="金额汇总" align="center" prop="jumboPlatesValueSubtotal" />
      <el-table-column label="备注" align="center" prop="memo" />
      <el-table-column label="冲单标志" align="center" prop="undoFlag" />
      <el-table-column label="审核人" align="center" prop="checker" />
      <el-table-column label="车台号" align="center" prop="rackId" />
      <el-table-column label="生产线" align="center" prop="floatLine" />
      <el-table-column label="重量汇总" align="center" prop="jumboPlatesWeightSubtotal" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="玻璃额外信息" align="center" prop="glassAdditionalInformation" />
      <el-table-column label="钢类型" align="center" prop="ironStandType" />
      <el-table-column label="数量" align="center" prop="deductionSqm" />
      <el-table-column label="列" align="center" prop="rows" />
      <el-table-column label="删除时间" align="center" prop="inputDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inputDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:in:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:in:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改原片入库对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="入库单号" prop="jumboPlatesStockInId">
          <el-input v-model="form.jumboPlatesStockInId" placeholder="请输入入库单号" />
        </el-form-item>
        <el-form-item label="原片ID" prop="jumboPlatesId">
          <el-input v-model="form.jumboPlatesId" placeholder="请输入原片ID" />
        </el-form-item>
        <el-form-item label="宽度" prop="jumboPlatesWidth">
          <el-input v-model="form.jumboPlatesWidth" placeholder="请输入宽度" />
        </el-form-item>
        <el-form-item label="高度" prop="jumboPlatesHeight">
          <el-input v-model="form.jumboPlatesHeight" placeholder="请输入高度" />
        </el-form-item>
        <el-form-item label="质量等级" prop="jumboPlatesQualityLevel">
          <el-input v-model="form.jumboPlatesQualityLevel" placeholder="请输入质量等级" />
        </el-form-item>
        <el-form-item label="入库箱数" prop="jumboPlatesStockInBoxQuantity">
          <el-input v-model="form.jumboPlatesStockInBoxQuantity" placeholder="请输入入库箱数" />
        </el-form-item>
        <el-form-item label="入数" prop="jumboPlatesPiecePerBox">
          <el-input v-model="form.jumboPlatesPiecePerBox" placeholder="请输入入数" />
        </el-form-item>
        <el-form-item label="散片数量" prop="jumboPlatesStockInUnpackaged">
          <el-input v-model="form.jumboPlatesStockInUnpackaged" placeholder="请输入散片数量" />
        </el-form-item>
        <el-form-item label="单价" prop="jumboPlatesPrice">
          <el-input v-model="form.jumboPlatesPrice" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="仓库ID" prop="stockId">
          <el-input v-model="form.stockId" placeholder="请输入仓库ID" />
        </el-form-item>
        <el-form-item label="货位ID" prop="positionId">
          <el-input v-model="form.positionId" placeholder="请输入货位ID" />
        </el-form-item>
        <el-form-item label="制造商ID" prop="manfactureId">
          <el-input v-model="form.manfactureId" placeholder="请输入制造商ID" />
        </el-form-item>
        <el-form-item label="供应商ID" prop="supplierId">
          <el-input v-model="form.supplierId" placeholder="请输入供应商ID" />
        </el-form-item>
        <el-form-item label="入库日期" prop="jumboPlatesStockInDate">
          <el-date-picker clearable
            v-model="form.jumboPlatesStockInDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入库日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产日期" prop="jumboPlatesProductionDate">
          <el-date-picker clearable
            v-model="form.jumboPlatesProductionDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择生产日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数量汇总" prop="jumboPlatesQuantitySubtotal">
          <el-input v-model="form.jumboPlatesQuantitySubtotal" placeholder="请输入数量汇总" />
        </el-form-item>
        <el-form-item label="面积汇总" prop="jumboPlatesSurfaceSubtotal">
          <el-input v-model="form.jumboPlatesSurfaceSubtotal" placeholder="请输入面积汇总" />
        </el-form-item>
        <el-form-item label="金额汇总" prop="jumboPlatesValueSubtotal">
          <el-input v-model="form.jumboPlatesValueSubtotal" placeholder="请输入金额汇总" />
        </el-form-item>
        <el-form-item label="备注" prop="memo">
          <el-input v-model="form.memo" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="冲单标志" prop="undoFlag">
          <el-input v-model="form.undoFlag" placeholder="请输入冲单标志" />
        </el-form-item>
        <el-form-item label="审核人" prop="checker">
          <el-input v-model="form.checker" placeholder="请输入审核人" />
        </el-form-item>
        <el-form-item label="车台号" prop="rackId">
          <el-input v-model="form.rackId" placeholder="请输入车台号" />
        </el-form-item>
        <el-form-item label="生产线" prop="floatLine">
          <el-input v-model="form.floatLine" placeholder="请输入生产线" />
        </el-form-item>
        <el-form-item label="重量汇总" prop="jumboPlatesWeightSubtotal">
          <el-input v-model="form.jumboPlatesWeightSubtotal" placeholder="请输入重量汇总" />
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="玻璃额外信息" prop="glassAdditionalInformation">
          <el-input v-model="form.glassAdditionalInformation" placeholder="请输入玻璃额外信息" />
        </el-form-item>
        <el-form-item label="数量" prop="deductionSqm">
          <el-input v-model="form.deductionSqm" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="列" prop="rows">
          <el-input v-model="form.rows" placeholder="请输入列" />
        </el-form-item>
        <el-form-item label="删除时间" prop="inputDate">
          <el-date-picker clearable
            v-model="form.inputDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择删除时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listIn, getIn, delIn, addIn, updateIn } from "@/api/system/in"

export default {
  name: "In",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 原片入库表格数据
      inList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jumboPlatesStockInId: null,
        jumboPlatesId: null,
        jumboPlatesWidth: null,
        jumboPlatesHeight: null,
        jumboPlatesQualityLevel: null,
        jumboPlatesStockInBoxQuantity: null,
        jumboPlatesPiecePerBox: null,
        jumboPlatesStockInUnpackaged: null,
        jumboPlatesPrice: null,
        jumboPlatesStockInType: null,
        stockId: null,
        positionId: null,
        manfactureId: null,
        supplierId: null,
        jumboPlatesStockInDate: null,
        jumboPlatesProductionDate: null,
        jumboPlatesQuantitySubtotal: null,
        jumboPlatesSurfaceSubtotal: null,
        jumboPlatesValueSubtotal: null,
        memo: null,
        undoFlag: null,
        checker: null,
        rackId: null,
        floatLine: null,
        jumboPlatesWeightSubtotal: null,
        userId: null,
        glassAdditionalInformation: null,
        ironStandType: null,
        deductionSqm: null,
        rows: null,
        inputDate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "用户id不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询原片入库列表 */
    getList() {
      this.loading = true
      listIn(this.queryParams).then(response => {
        this.inList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        keyId: null,
        jumboPlatesStockInId: null,
        jumboPlatesId: null,
        jumboPlatesWidth: null,
        jumboPlatesHeight: null,
        jumboPlatesQualityLevel: null,
        jumboPlatesStockInBoxQuantity: null,
        jumboPlatesPiecePerBox: null,
        jumboPlatesStockInUnpackaged: null,
        jumboPlatesPrice: null,
        jumboPlatesStockInType: null,
        stockId: null,
        positionId: null,
        manfactureId: null,
        supplierId: null,
        jumboPlatesStockInDate: null,
        jumboPlatesProductionDate: null,
        jumboPlatesQuantitySubtotal: null,
        jumboPlatesSurfaceSubtotal: null,
        jumboPlatesValueSubtotal: null,
        memo: null,
        undoFlag: null,
        checker: null,
        rackId: null,
        floatLine: null,
        jumboPlatesWeightSubtotal: null,
        userId: null,
        glassAdditionalInformation: null,
        ironStandType: null,
        deductionSqm: null,
        rows: null,
        inputDate: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.keyId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加原片入库"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const keyId = row.keyId || this.ids
      getIn(keyId).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改原片入库"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.keyId != null) {
            updateIn(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addIn(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const keyIds = row.keyId || this.ids
      this.$modal.confirm('是否确认删除原片入库编号为"' + keyIds + '"的数据项？').then(function() {
        return delIn(keyIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/in/export', {
        ...this.queryParams
      }, `in_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
